﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Engine.Sgml {
    static class EntityManager {
        public static void PushEntity(EntityReader reader, Entity entity) {
            Guard.ArgumentNotNull(reader, "reader");
            entity.Open(reader.Entity);
            reader.Entity = entity;
            }

        public static void PushEntity(EntityReader reader, string name, string literal) {
            Guard.ArgumentNotNull(reader, "reader");
            Guard.ArgumentNotNull(literal, "literal");

            Entity entity = new Entity(name, literal);
            entity.Open(reader.Entity);
            reader.Entity = entity;
            reader.ReadChar();
            }

        public static void PopEntity(EntityReader reader) {
            Guard.ArgumentNotNull(reader, "reader");
            if (reader.Entity == null)
                throw new InvalidOperationException();
            Entity entity = reader.Entity;
            if (entity.Parent != null)
                reader.Entity = entity.Parent;
            }
        }
    }
